package com.fhj.movie.activity;

import com.lidroid.xutils.view.annotation.ViewInject;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

public class MyWebViewClient extends WebViewClient {
	private HyyItemClick activity;
	private ImageView progress;
	private Animation loadAnimation;
	public MyWebViewClient(HyyItemClick ac,ImageView progress,Animation loadAnimation) {
		// TODO Auto-generated constructor stub
		activity=ac;
		this.progress=progress;
		this.loadAnimation =loadAnimation;
	}

	@Override
	public void onPageStarted(WebView view, String url, Bitmap favicon) {
		if (activity != null) {
			if (favicon != null) {
				activity.setFeatureDrawable(Window.FEATURE_LEFT_ICON,
						new BitmapDrawable(activity.getResources(), favicon));
				
			}
			
			activity.setLoadingButtonSate(1);
			progress.startAnimation(loadAnimation);
			progress.setVisibility(View.VISIBLE);
		}
		
	}
	@Override
	public void onPageFinished(WebView view, String url) {
		if(activity!=null){
			activity.setLoadingButtonSate(0);
			progress.clearAnimation();
			progress.setVisibility(View.INVISIBLE);
		}
	}
	@Override
	public void onReceivedError(WebView view, int errorCode,
			String description, String failingUrl) {
		if(activity!=null){
			activity.setLoadingButtonSate(0);
			loadAnimation.cancel();
			progress.setVisibility(View.INVISIBLE);
		}
	}
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		// TODO Auto-generated method stub
		
		return super.shouldOverrideUrlLoading(view, url);
	}
	
}
